package pers.qianyu.module.image.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.module.core.comm.HttpResult;
import pers.qianyu.module.core.comm.Pagination;
import pers.qianyu.module.core.domain.image.dataobj.LabelCountDO;
import pers.qianyu.module.core.domain.image.query.LabelQuery;
import pers.qianyu.module.core.domain.image.vo.ImageVO;
import pers.qianyu.module.core.domain.image.vo.LabelVO;
import pers.qianyu.module.image.service.LabelService;
import pers.qianyu.module.logging.annotation.ControllerLog;
import pers.qianyu.module.logging.enums.BusinessType;

import java.util.Set;

/**
 * 标签Controller，暂时使用图片表中的数据，后期可能进行修改
 *
 * @author mizzle rain
 * @date 2021-04-07 11:53
 */
@Api(tags = "标签相关接口")
@RequestMapping("/image-serv")
@RestController
public class LabelController {
    @Autowired
    private LabelService labelService;

    @ApiOperation("查询所有标签集合")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/labels")
    public HttpResult<Set<LabelCountDO>> getAllLabels() {
        Set<LabelCountDO> labels = labelService.getAllLabels();
        return HttpResult.okWithData(labels);
    }

    @ApiOperation("根据标签ID删除标签信息，同时删除该标签相关的所有图片")
    @ControllerLog(businessType = BusinessType.DELETE)
    @DeleteMapping("/label/{id}")
    public HttpResult<?> deleteById(@PathVariable("id") Long id) {
        labelService.deleteById(id);
        return HttpResult.okWithMessage("标签删除成功");
    }

    @ApiOperation("分页查询含有该标签的图片")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/label_images")
    public HttpResult<Pagination<ImageVO>> getImagesByLabel(LabelQuery labelQuery) {
        Pagination<ImageVO> pagination = labelService.findImagesByLabel(labelQuery);
        return HttpResult.okWithData(pagination);
    }

    @ApiOperation("分页查询标签信息")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/labels_page")
    public HttpResult<Pagination<LabelVO>> getPageLabel(LabelQuery labelQuery) {
        Pagination<LabelVO> page = labelService.pageQuery(labelQuery);
        return HttpResult.okWithData(page);
    }
}
